﻿using System;
using System.Linq;
using fastCSharp;

namespace diantou.web.management
{
    /// <summary>
    /// 内存对象关系图
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPage = false, IsPool = true)]
    partial class memoryGraph : adminView<memoryGraph> 
    {
        /// <summary>
        /// 是否考试域名
        /// </summary>
        private bool isExam;
        /// <summary>
        /// 数据服务内存信息
        /// </summary>
        private diantou.dataAccess.memory dataServerMemory
        {
            get
            {
                return isExam ? diantou.examDataAccess.tcpCall.memory.memoryInfo : diantou.dataAccess.tcpCall.memory.memoryInfo;
            }
        }
        /// <summary>
        /// HTTP服务内存信息
        /// </summary>
        private diantou.dataAccess.memory httpServerMemory
        {
            get { return diantou.dataAccess.memory.MemoryInfo; }
        }
        /// <summary>
        /// 
        /// </summary>
        private int freeMemory
        {
            get
            {
                return (int)(fastCSharp.memoryGraph.GetMemoryInfo().Avail >> 20);
            }
        }
        /// <summary>
        /// HTTP响应输出缓冲区数量
        /// </summary>
        private int httpResponseCount
        {
            get { return fastCSharp.net.tcp.http.response.NewCount; }
        }
        /// <summary>
        /// HTTP响应输出缓冲区数量
        /// </summary>
        private int httpResponsePoolNewCount
        {
            get { return fastCSharp.net.tcp.http.response.PoolNewCount; }
        }
        /// <summary>
        /// HTTP响应输出缓冲区池空闲数量
        /// </summary>
        private int httpResponsePoolCount
        {
            get { return typePool<fastCSharp.net.tcp.http.response>.Count(); }
        }
        /// <summary>
        /// HTTP套接字数量
        /// </summary>
        private int httpSocketCount
        {
            get { return fastCSharp.net.tcp.http.socketBase.NewCount; }
        }
        /// <summary>
        /// HTTP套接字安全流数量
        /// </summary>
        private int httpsSocketCount
        {
            get { return fastCSharp.net.tcp.http.socketBase.NewSslCount; }
        }
        /// <summary>
        /// HTTP套接字排队次数
        /// </summary>
        private int httpSocketQueueCount
        {
            get { return fastCSharp.net.tcp.http.socketBase.QueueCount; }
        }
        /// <summary>
        /// HTTP套接字池空闲数量
        /// </summary>
        private int httpSocketPoolCount
        {
            get { return fastCSharp.net.tcp.http.socketBase.PoolCount; }
        }
        ///// <summary>
        ///// HTTP套接字超时次数
        ///// </summary>
        //private int httpSocketTimeoutCount
        //{
        //    get { return fastCSharp.net.tcp.http.socketBase.TimeoutCount; }
        //}
        /// <summary>
        /// HTTPS套接字池空闲数量
        /// </summary>
        private int httpsSocketPoolCount
        {
            get { return fastCSharp.net.tcp.http.socketBase.SslPoolCount; }
        }
        /// <summary>
        /// HTTPS套接字排队次数
        /// </summary>
        private int httpsSocketQueueCount
        {
            get { return fastCSharp.net.tcp.http.socketBase.SslQueueCount; }
        }
        /// <summary>
        /// HTTP服务每秒请求数量
        /// </summary>
        private float httpSecondCount
        {
            get
            {
                int[] counts = fastCSharp.net.tcp.http.socketBase.SecondCount;
                return counts.Length == 0 ? 0 : ((float)counts.Sum() / counts.Length);
            }
        }
        /// <summary>
        /// HTTP服务每秒请求数量最大值
        /// </summary>
        private int httpSecondCountMax
        {
            get { return fastCSharp.net.tcp.http.socketBase.SecondCount.max(0); }
        }
        /// <summary>
        /// HTTP服务每秒响应数量
        /// </summary>
        private float httpResponseSecondCount
        {
            get
            {
                int[] counts = fastCSharp.net.tcp.http.socketBase.ResponseSecondCount;
                return counts.Length == 0 ? 0 : ((float)counts.Sum() / counts.Length);
            }
        }
        /// <summary>
        /// HTTP服务每秒响应数量
        /// </summary>
        private int httpResponseSecondCountMax
        {
            get { return fastCSharp.net.tcp.http.socketBase.ResponseSecondCount.max(0); }
        }
        /// <summary>
        /// 每秒动态请求数量(不包括搜索引擎)
        /// </summary>
        private float webCallSecondCount
        {
            get
            {
                int[] counts =  fastCSharp.net.tcp.http.domainServer.viewServer.SecondCount;
                return counts.Length == 0 ? 0 : ((float)counts.Sum() / counts.Length);
            }
        }
        /// <summary>
        /// 每秒动态请求数量(不包括搜索引擎)
        /// </summary>
        private int webCallSecondCountMax
        {
            get { return fastCSharp.net.tcp.http.domainServer.viewServer.SecondCount.max(0); }
        }
        /// <summary>
        /// WebView每秒请求数量
        /// </summary>
        private float webViewSecondCount
        {
            get
            {
                int[] counts = fastCSharp.code.cSharp.webPage.pageBase.SecondCount;
                return counts.Length == 0 ? 0 : ((float)counts.Sum() / counts.Length);
            }
        }
        /// <summary>
        /// WebView每秒请求数量
        /// </summary>
        private int webViewSecondCountMax
        {
            get { return fastCSharp.code.cSharp.webPage.pageBase.SecondCount.max(0); }
        }
        /// <summary>
        /// 长连接每秒请求数量
        /// </summary>
        private float pollSecondCount
        {
            get
            {
                if (isExam) return 0;
                int[] counts = poll.SecondCount.Counts;
                return counts.Length == 0 ? 0 : ((float)counts.Sum() / counts.Length);
            }
        }
        /// <summary>
        /// 长连接每秒请求数量
        /// </summary>
        private int pollSecondCountMax
        {
            get
            {
                if (isExam) return 0;
                return poll.SecondCount.Counts.max(0);
            }
        }
        ///// <summary>
        ///// HTTPS套接字超时次数
        ///// </summary>
        //private int httpsSocketTimeoutCount
        //{
        //    get { return fastCSharp.net.tcp.http.socketBase.SslTimeoutCount; }
        //}
        /// <summary>
        /// 长连接数量
        /// </summary>
        private int pollCount
        {
            get { return diantou.web.poll.AsynchronousCount; }
        }
        /// <summary>
        /// 长连接用户数量
        /// </summary>
        private int pollUserCount
        {
            get
            {
                if (isExam) return 0;
                return diantou.dataAccess.tcpCall.user.onNoticeChangeCount; 
            }
        }
        /// <summary>
        /// 长连接企业用户数量
        /// </summary>
        private int pollEnterpriseCount
        {
            get
            {
                if (isExam) return 0;
                return diantou.examDataAccess.tcpCall.enterprise.onEnterpriseNoticeChangeCount;
            }
        }
        /// <summary>
        /// 长连接轮询队列最大线程数量
        /// </summary>
        private int pollQueueTaskMaxThreadCount
        {
            get
            {
                if (isExam) return 0;
                return diantou.dataAccess.tcpCall.poll.getQueueTaskMaxThreadCount();
            }
        }
        /// <summary>
        /// 长连接轮询队列最大线程数量
        /// </summary>
        private int examPollQueueTaskMaxThreadCount
        {
            get
            {
                if (isExam) return 0;
                return diantou.examDataAccess.tcpCall.enterprisePoll.getQueueTaskMaxThreadCount();
            }
        }
        /// <summary>
        /// 考试长连接数量
        /// </summary>
        private int examPollCount
        {
            get
            {
                if (isExam) return exam.problem.AnswerCacheClient.UserCount;
                return 0;
            }
        }
        /// <summary>
        /// 页面Path集合
        /// </summary>
        private string[] pagePaths = nullValue<string>.Array;
        /// <summary>
        /// 加载错误页面Path集合
        /// </summary>
        private string[] errorPaths = nullValue<string>.Array;
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override bool loadView()
        {
            if (base.loadView())
            {
                isExam = requestHeader.Host.simpleEqual(ref index.ExamDomain);
                return true;
            }
            return false;
        }
    }
}
